<template>
    <kr-print-designer ref="printDesigner" :temp-value="value" :widget-options="widgets" @save="handleSave" />
</template>
<script>
import { SavePrintTemp } from "@/service/baseapi";
export default {
    data() {
        return {
            index: "",
            value: {},
            widgets: []
        };
    },

    created() {
        var data = this.$route.params.zqh;
        console.log(data);
        data.tempItems = JSON.parse(data.tempItems);
        this.value = data;
        this.widgets = JSON.parse(data.assembly);
    },
    methods: {
        handleSave(e) {
            console.log(e);
            var that = this;
            e.tempItems = JSON.stringify(e.tempItems);
            SavePrintTemp(e)
                .then(res => {
                    that.$message({ message: "操作成功", type: "success" });
                    that.$router.back();
                })
                .catch(err => {
                    that.$message.error("操作失败");
                    that.closeLoading();
                });
            // this.$router.back()
        },
        // 手动初始话模板数据
        initTemp() {
            this.$refs.printDesigner.initTemp(this.value, this.widgets);
        }
    }
};
</script>
